package com.dragon.app.IO;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;

public class DataStream {

	public static void main(String[] args) throws IOException {
		
		ByteArrayOutputStream baos1 = new ByteArrayOutputStream();
		ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
		ByteArrayOutputStream baos3 = new ByteArrayOutputStream();
		ByteArrayOutputStream baos4 = new ByteArrayOutputStream();
		ByteArrayOutputStream baos5 = new ByteArrayOutputStream();
		ByteArrayOutputStream baos6 = new ByteArrayOutputStream();
		ByteArrayOutputStream baos7 = new ByteArrayOutputStream();
		ByteArrayOutputStream baos8 = new ByteArrayOutputStream();
		ByteArrayOutputStream baos9 = new ByteArrayOutputStream();
		DataOutputStream dos1 = new DataOutputStream(baos1);
		DataOutputStream dos2 = new DataOutputStream(baos2);
		DataOutputStream dos3 = new DataOutputStream(baos3);
		DataOutputStream dos4 = new DataOutputStream(baos4);
		DataOutputStream dos5 = new DataOutputStream(baos5);
		DataOutputStream dos6 = new DataOutputStream(baos6);
		DataOutputStream dos7 = new DataOutputStream(baos7);
		DataOutputStream dos8 = new DataOutputStream(baos8);
		DataOutputStream dos9 = new DataOutputStream(baos9);
		
		dos1.writeByte(9);
		dos2.writeShort(9);
		dos3.writeInt(9);
		dos4.writeLong(9);
		dos5.writeBoolean(true); //boolean所占字节可以得到
		dos6.writeChar('a');
		dos7.writeFloat(9);
		dos8.writeDouble(9);
		dos9.writeBoolean(new Boolean(true));
		
		System.out.println("一个byte所占字节："+baos1.toByteArray().length);
		System.out.println("一个short所占字节："+baos2.toByteArray().length);
		System.out.println("一个int所占字节："+baos3.toByteArray().length);
		System.out.println("一个long所占字节："+baos4.toByteArray().length);
		System.out.println("一个boolean所占字节："+baos5.toByteArray().length);
		System.out.println("一个char所占字节："+baos6.toByteArray().length);
		System.out.println("一个float所占字节："+baos7.toByteArray().length);
		System.out.println("一个double所占字节："+baos8.toByteArray().length);
		System.out.println(baos9.toByteArray().length);
		
		
	}

}
